package com.qf.controller;

import com.github.pagehelper.PageInfo;
import com.qf.entity.Result;
import com.qf.entity.User;
import com.qf.service.UserService;
import com.qf.vo.UserVO;
import com.qf.vo.UserVOfenye;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author TZL
 * @date 2020/8/6
 */
@Controller
public class HelloController {
    @RequestMapping("/hello")
    @ResponseBody
    public String hello(){
        System.out.println("hello boot");
        return "hello Boot";
    }

    @Autowired
    UserService userService;
    //查询用户 ps：还没做分页
    @RequestMapping("/users")
    @ResponseBody
    public UserVOfenye queryAll(int page, int limit){
        List<User> users = userService.queryAllUsers(page,limit);
        int count = userService.usercount();
        return new UserVOfenye(0,"成功",users,count);
    }


    //修改用户
    @PutMapping("/upuser")
    @ResponseBody
    public Result updateuser(@RequestBody User user){
        userService.updateUser(user);
        return Result.ok();
    }
    //删除用户
    @DeleteMapping("/deluser/{id}")
    @ResponseBody
    public Result deluser(@PathVariable int id){
        userService.deleteUser(id);
        return Result.ok();
    }
    //增+
    @PostMapping("/insertuser")
    @ResponseBody
    public Result insertuser(@RequestBody User user){
        userService.insertUser(user);
        return Result.ok();
    }




}

